package vip.meeet.lifecycle;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * 1. BeanPostProcessor的作用域是容器级的，它只和所在容器有关
 * 2. BeanFactory和ApplicationContext对待bean后置处理器稍有不同
   3. ApplicationContext会自动检测在配置文件中实现了BeanPostProcessor接口的所有bean
	并把它们注册为后置处理器，然后在容器创建bean的适当时候调用它。部署一个后置处理器同部署其他的bean并没有什么区别

   4. 而使用BeanFactory实现的时候，bean 后置处理器必须通过下面类似的代码显式地去注册：
    BeanPostPrcessorImpl beanPostProcessor = new BeanPostPrcessorImpl();  
    Resource resource = new FileSystemResource("applicationContext.xml");  
    ConfigurableBeanFactory factory = new XmlBeanFactory(resource);  
    factory.addBeanPostProcessor(beanPostProcessor);  
    factory.getBean("beanName");  
 *  5. 2个相近的接口：
 *		InstantiationAwareBeanPostProcessorAdapter
 *		InstantiationAwareBeanPostProcessor
 *		BeanFactoryPostProcessor(BeanFactoryPostProcessor的回调比BeanPostProcessor早)
 */

public class DealProxyBean implements BeanPostProcessor{
	
	private static final String thisClassName = BeanPostProcessor.class.getName();
	
	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		System.out.println(LifeCycleBean.sequence.getAndIncrement() + " " + thisClassName + "#"  + "postProcessBeforeInitialization");
//		System.out.println(beanName);
		return bean;
	}

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		System.out.println(LifeCycleBean.sequence.getAndIncrement() + " " + thisClassName + "#"  + "postProcessAfterInitialization");
//		System.out.println(beanName);
		return bean;
	}

	

}
